-module(testing).
-compile(export_all).



insert_values(Values) ->
    _R = [node:put(X,X)
         || X <- Values],
    {ok, inserted}.


get_and_check_values([V|Vs]) ->
    Reply = node:get(V),
    case Reply of
        {_,Value} -> (Value == V) and get_and_check_values(Vs);
        _           -> io:format("Error: ~w~n", [V]),
                       false
    end;
get_and_check_values([]) ->
    true. 



generate_values(N) ->
    [get_random_string(5,"abcefghijklmnopqrstuvwxyz")
    || _ <- lists:seq(0,N)].



get_random_string(Length, AllowedChars) ->
    lists:foldl(fun(_, Acc) ->
                        [lists:nth(random:uniform(length(AllowedChars)),
                                   AllowedChars)]
                            ++ Acc
                end, [], lists:seq(1, Length)).
